import io.grpc.NameResolver;
import io.grpc.NameResolverProvider;

import javax.annotation.Nullable;
import java.net.URI;
import java.util.Map;

public class LocalNameResolverProvider extends NameResolverProvider {
    private final Map<String, Object>  config;

    public LocalNameResolverProvider(Map<String, Object> config) {
        this.config = config;
    }

    // 服务是否可用
    @Override
    protected boolean isAvailable() {
        return true;
    }

    // 优先级默认5
    @Override
    protected int priority() {
        return 5;
    }
    // 服务发现类
    @Nullable
    @Override
    public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
        return new LocalNameResolver(config);
    }

    // 服务协议
    @Override
    public String getDefaultScheme() {
        return "local";
    }
}
